{{extend '../layout.html'}} {{block 'title'}}{{title}}{{/block}} {{block 'head'}}{{/block}} {{block 'content'}}

<div class="container">

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">添加用户</h3>
        </div>
        <div class="panel-body">

            <form class="form-horizontal" id="addForm">
                <div class="form-group">
                    <label for="loginname" class="col-sm-2 control-label">账号：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="loginname" name="loginname" placeholder="请输入账号" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="col-sm-2 control-label">密码：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="password" name="password" placeholder="请输入密码" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">姓名：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请输入姓名" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sex" class="col-sm-2 control-label">性别：</label>
                    <div class="col-sm-10">
                        <input type="radio" id="sex1" name="sex" value="true"> 男 &nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" id="sex2" name="sex" value="false" checked> 女
                    </div>
                </div>
                <div class="form-group">
                    <label for="age" class="col-sm-2 control-label">年龄：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="age" name="age" placeholder="请输入年龄" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="birthday" class="col-sm-2 control-label">出生日期：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="birthday" name="birthday" placeholder="请输入出生日期" required>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" id="btnSave" class="btn btn-default">保存</button>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>


<div class="modal fade" id="modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {

        $('#btnSave').click(function (ev) {
            ev.preventDefault();

            $.post("/user/post", $('#addForm').serialize(), function (res) {
                if (res.code == 200) {
                    location.href = '/';
                } else {
                    $('#modal .modal-body').text(res.message);
                    $('#modal').modal();
                }
            })
        })

    })

</script>

{{/block}}